package com.tqjc.business.interactivewithscan.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 四边形顶点
 */
@Data
public class QuadrilateralVertex {
    /**
     * 左上角
     */
    private Coord leftUpper;
    /**
     * 左下角
     */
    private Coord leftLower;
    /**
     * 右上角
     */
    private Coord rightUpper;
    /**
     * 右下角
     */
    private Coord rightLower;

    private Integer safeDistance = 200;

    public Integer getMaxX() {
        List<Integer> xs = new ArrayList<>();
        xs.add(leftUpper.getX());
        xs.add(leftLower.getX());
        xs.add(rightUpper.getX());
        xs.add(rightLower.getX());
        xs.remove(Collections.max(xs));
        int maxX = Collections.max(xs) - safeDistance;
        return maxX;
    }

    public Integer getMinX() {
        List<Integer> xs = new ArrayList<>();
        xs.add(leftUpper.getX());
        xs.add(leftLower.getX());
        xs.add(rightUpper.getX());
        xs.add(rightLower.getX());
        xs.remove(Collections.min(xs));
        int minX = Collections.min(xs) + safeDistance;
        return minX;
    }

    public Integer getMaxY() {
        List<Integer> ys = new ArrayList<>();
        ys.add(leftUpper.getY());
        ys.add(leftLower.getY());
        ys.add(rightUpper.getY());
        ys.add(rightLower.getY());
        ys.remove(Collections.max(ys));
        int maxY = Collections.max(ys) - safeDistance;
        return maxY;
    }

    public Integer getMinY() {
        List<Integer> ys = new ArrayList<>();
        ys.add(leftUpper.getY());
        ys.add(leftLower.getY());
        ys.add(rightUpper.getY());
        ys.add(rightLower.getY());
        ys.remove(Collections.min(ys));
        int minY = Collections.min(ys) + safeDistance;
        return minY;
    }

}
